package lablayer.model.MathComponents;

import lablayer.model.LabData;

/**
 * @author Darkness
 */

/*
 * Component #14
 *
 * Length of intervals for array
 */
public class IntervalLength implements MathComponent {
	private LabData result;

	private LabData data;

	private String componentName = "Длина интервала";

	private String componentId = "14";

	@Override
	public LabData getData() {
		return this.data;
	}

	@Override
	public void calculate() {
		try {
			Double[] row = this.data.getData()[0][0];
			Double intervalCount = this.data.getData()[0][1][0];
			Double minValue = 0.0;
			Double maxValue = 0.0;
			LabData data = new LabData(row);
			MathComponent minValueCom = MathComponentFactory.createMinValue();
			MathComponent maxValueCom = MathComponentFactory.createMaxValue();

			minValueCom.setData(data);
			maxValueCom.setData(data);
			minValueCom.calculate();
			maxValueCom.calculate();

			minValue = (minValueCom.getResult().getData())[0][0][0];
			maxValue = (maxValueCom.getResult().getData())[0][0][0];

			Double intervalLength = (maxValue - minValue) / intervalCount;
			this.result = new LabData(intervalLength);
		} catch (Exception e) {}
	}

	@Override
	public void setData(LabData data) {
		try {
			assert data != null : "";
			this.data = data;
		} catch (Exception e) {}
	}

	@Override
	public String getComponentId() {
		return this.componentId;
	}

	@Override
	public String getComponentName() {
		return this.componentName;
	}

	@Override
	public LabData getResult() {
		return this.result;
	}

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

}
